/****************************************************************************

 Copyright (C) 2009 Jean Pierre Charalambos. All rights reserved.

 Jean Pierre Charalambos (http://dis.unal.edu.co/profesores/pierre/) is an
 Affiliate Associate Professor of the Faculty of Engineering at National
 University of Colombia (http://www.unal.edu.co/).

 This file is part of maku version 0.1.

 http://code.google.com/p/maku/
 email: jpcharalambosh@unal.edu.co

 This file may be used under the terms of the GNU General Public License 
 versions 2.0 or 3.0 as published by the Free Software Foundation and
 appearing in the COPYING file included in the packaging of this file.

 This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

*****************************************************************************/

#ifndef BOUNDINGBOXT_H
#define BOUNDINGBOXT_H

//openmesh:
#include <OpenMesh/Core/Utils/vector_cast.hh>

// base class:
#include "boundingbox.h"

using namespace OpenMesh;

/**
@author Jean Pierre Charalambos
*/
template <typename M>
class BoundingBoxT : public BoundingBox
{
public:
    typedef M                             Mesh;
    BoundingBoxT() : BoundingBox() {};
    //caution!! Point should be the same type found in VectorT< float, 3 > (that is Vec3f) in base class
    BoundingBoxT(const typename Mesh::Point & pmin, const typename Mesh::Point & pmax) : BoundingBox(pmin, pmax) {};
    virtual ~BoundingBoxT(){}
    virtual void setFromMesh( const Mesh & mesh ) {
      typename Mesh::ConstVertexIter vIt(mesh.vertices_begin());
      typename Mesh::ConstVertexIter vEnd(mesh.vertices_end());
      bbMin = bbMax = OpenMesh::vector_cast<Vec3f >(mesh.point(vIt));
      for (size_t count=0; vIt!=vEnd; ++vIt, ++count) {
        bbMin.minimize( OpenMesh::vector_cast<Vec3f >(mesh.point(vIt)));
        bbMax.maximize( OpenMesh::vector_cast<Vec3f >(mesh.point(vIt)));
      }
      setAll();
    }
};

#endif
